from PIL import Image, ImageSequence
import os
# 网上找的代码，好像有一丢丢问题，生成的反转图片的速率好像变了？而且怎么有两张图多了黑边
for i in os.listdir():
    if i.endswith(".gif") and not i.endswith("（反）.gif"):
        with Image.open(i) as im:
            if im.is_animated:
                frames = [f.copy() for f in ImageSequence.Iterator(im)]
                frames.reverse()
                frames[0].save(i.split(".gif")[0] + "（反）.gif", save_all=True, append_images=frames[1:])
